<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- <button v-on:click="fun(100)">click</button> -->
         <input type="text" v-model="val">
         <button @click="addList()">添加</button>
        <ul>
            <li  v-for="(item,index) in list " :key="index" v-on:click="demo(item.id)">{{item.name}}--{{index}}</li>
        </ul>
    </div>
    <!-- 
        v-on用于点击事件
    -->
</body>
<script >
    let vm = new Vue({
        el:"#app",
        data:{
            val:"",
            list:[
                {
                    name:"张三",
                    age:18,
                    id:1
                },
                {
                    name:"李四",
                    age:80,
                    id:2
                }
            ]
        },
        methods:{
            fun(a){
                console.log(a)
            },
            demo(a){
                console.log(a)
                this.list.splice(a,1)
            },
            addList(){
                //data 里的变量 可以通过this 来访问
                console.log(this.val)
                let obj ={
                    name:this.val,
                    id:this.val.length+1
                }
                this.list.push(obj)
                this.val = ''
            }
        }
    })
</script>
</html>